//
//  UIButton+YJCSetting.m
//  MyDemos
//
//  Created by IOS3 on 2019/3/8.
//  Copyright © 2019 iMac. All rights reserved.
//

#import "UIButton+YJCSetting.h"

@implementation UIButton (YJCSetting)

/// set title for state
- (UIButton *(^)(NSString *title, UIControlState state))setTitle {
    __weak typeof(self)weakSelf = self;
    return ^(NSString *title, UIControlState state) {
        __strong typeof(weakSelf)strongSelf = weakSelf;
        [strongSelf setTitle:title forState:state];
        return strongSelf;
    };
}

/// set titleColor for state
- (UIButton *(^)(UIColor *color, UIControlState state))setTitleColor {
    __weak typeof(self)weakSelf = self;
    return ^(UIColor *color, UIControlState state) {
        __strong typeof(weakSelf)strongSelf = weakSelf;
        [strongSelf setTitleColor:color forState:state];
        return strongSelf;
    };
}

/// set backgroundColor
- (UIButton *(^)(UIColor *color))setBGColor {
    __weak typeof(self)weakSelf = self;
    return ^(UIColor *color) {
        __strong typeof(weakSelf)strongSelf = weakSelf;
        [strongSelf setBackgroundColor:color];
        return strongSelf;
    };
}

/// set imageName for state
- (UIButton *(^)(NSString *imageName, UIControlState state))setImage {
    __weak typeof(self)weakSelf = self;
    return ^(NSString *imageName, UIControlState state) {
        __strong typeof(weakSelf)strongSelf = weakSelf;
        [strongSelf setImage:[UIImage imageNamed:imageName] forState:state];
        return strongSelf;
    };
}

/// set background imageName for state
- (UIButton *(^)(NSString *imageName, UIControlState state))seBGtImage {
    __weak typeof(self)weakSelf = self;
    return ^(NSString *imageName, UIControlState state) {
        __strong typeof(weakSelf)strongSelf = weakSelf;
        [strongSelf setBackgroundImage:[UIImage imageNamed:imageName] forState:state];
        return strongSelf;
    };
}

/// set titleFont
- (UIButton *(^)(CGFloat size))setSysTitleFont {
    __weak typeof(self)weakSelf = self;
    return ^(CGFloat size) {
        __strong typeof(weakSelf)strongSelf = weakSelf;
        strongSelf.titleLabel.font = [UIFont systemFontOfSize:size];
        return strongSelf;
    };
}

/// set titleFont(name, size)
- (UIButton *(^)(NSString *name, CGFloat size))setNameTitleFont {
    __weak typeof(self)weakSelf = self;
    return ^(NSString *name, CGFloat size) {
        __strong typeof(weakSelf)strongSelf = weakSelf;
        strongSelf.titleLabel.font = [UIFont fontWithName:name size:size];
        return strongSelf;
    };
}


/// set frame
- (UIButton *(^)(CGRect frame))setFrame {
    __weak typeof(self)weakSelf = self;
    return ^(CGRect frame) {
        __strong typeof(weakSelf)strongSelf = weakSelf;
        strongSelf.frame = frame;
        return strongSelf;
    };
}


/// set tag
- (UIButton *(^)(NSInteger tag))setTag {
    __weak typeof(self)weakSelf = self;
    return ^(NSInteger tag) {
        __strong typeof(weakSelf)strongSelf = weakSelf;
        strongSelf.tag = tag;
        return strongSelf;
    };
}

@end
